package com.ruoyi.project.credentials.controller;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.security.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.credentials.domain.Credentials;
import com.ruoyi.project.credentials.service.ICredentialsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户证书Controller
 *
 * @author chenweiguo
 * @date 2020-05-05
 */
@RestController
@RequestMapping("/credentials/credentials")
public class CredentialsController extends BaseController {
    @Autowired
    private ICredentialsService credentialsService;

    /**
     * 查询用户证书列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Credentials credentials) {
        startPage();
        List<Credentials> list = credentialsService.selectCredentialsList(credentials);
        return getDataTable(list);
    }

    /**
     * 导出用户证书列表
     */
    @PreAuthorize("@ss.hasPermi('credentials:credentials:export')")
    @Log(title = "用户证书", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Credentials credentials) {
        List<Credentials> list = credentialsService.selectCredentialsList(credentials);
        ExcelUtil<Credentials> util = new ExcelUtil<Credentials>(Credentials.class);
        return util.exportExcel(list, "credentials");
    }

    /**
     * 获取用户证书详细信息
     */
    @PreAuthorize("@ss.hasPermi('credentials:credentials:query')")
    @GetMapping(value = "/{credentialsId}")
    public AjaxResult getInfo(@PathVariable("credentialsId") Long credentialsId) {
        return AjaxResult.success(credentialsService.selectCredentialsById(credentialsId));
    }

    /**
     * 新增用户证书
     */
    @PreAuthorize("@ss.hasPermi('credentials:credentials:add')")
    @Log(title = "用户证书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Credentials credentials) {
        return toAjax(credentialsService.insertCredentials(credentials));
    }

    /**
     * 修改用户证书
     */
    @PreAuthorize("@ss.hasPermi('credentials:credentials:edit')")
    @Log(title = "用户证书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Credentials credentials) {
        return toAjax(credentialsService.updateCredentials(credentials));
    }

    /**
     * 删除用户证书
     */
    @PreAuthorize("@ss.hasPermi('credentials:credentials:remove')")
    @Log(title = "用户证书", businessType = BusinessType.DELETE)
    @DeleteMapping("/{credentialsIds}")
    public AjaxResult remove(@PathVariable Long[] credentialsIds) {
        return toAjax(credentialsService.deleteCredentialsByIds(credentialsIds));
    }


}